import http from '@/utils/http'
import { GET_CART_LENGTH } from './../types'

const state = {
	cartLen: 0 
}

const actions = {
	getCartLen ({commit}) {
		commit(GET_CART_LENGTH)
	}
}

const mutations = {
	[GET_CART_LENGTH] (state) {
		http.get('/api/v1/cart', { isHideLoad: true }, false, res => {
			if (res.status == 1) {
				state.cartLen = res.data.length
			}
		})
	}
}

const getters = {
	// 获取购物车总数
	cartLen: state => {
		return state.cartLen
	}
}

export default {
	state,
 	getters,
 	mutations,
 	actions
}